<!DOCTYPE html>
<#assign secSelect = JspTaglibs["http://www.casic304.cn/secSelect"] />
<#assign fillDept=JspTaglibs["http://www.casic304.cn/fillDept"] />
<#assign dicSelect = JspTaglibs["http://www.casic304.cn/dicSelect"]/>

<html>
<head>
    <meta charset="utf-8">
    <title>质量知识基本信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
    <style>

        @media screen and (min-width: 1280px){
            .containDIv{
                width: 30%;
            }
            .containDIv56{
                width: 56%;
            }
        }
        @media screen and (min-width: 804px) and (max-width:1280px){
            .containDIv{
                width:82%;
            }
            .aa{
                width: 83%;
            }
        }
        .qbdms-TBinformationText{
            margin-left: 108px;
        }
        .qbdms-TBinformation{
            width: 62px;
            margin-left: 45px;
        }
        .qbdms-label{
            text-align: right;
        }
        .qbdms-input{
            margin-left: 114px;
        }
    </style>
</head>
<body class="listBody">
    <div class="qbdms-bodyDiv" >
        <div class="qbdms-backDiv">
        <div class="layui-table-view-body" style="padding: 0 24px 24px;">
            <div class="qbdms-formTitle" style="border-bottom: 1px solid #E5F0FF">质量知识 <i class="qbdms-returnOn closeWindow">返回</i></div>
            <form class="layui-form formPreview"  requrl="${ctx}/qbdms/wQbdQualityKnow/get"  lay-filter="wQbdQualityKnowDataForm" style="padding:24px 0 0 80px">
                <div class="dragInfo temSpace" colspan="2" rowspan="1" id="tbxx"></div>
                <div class="layui-row">
                    <@fillDept.dept css="dragInfo temSpace" id="tbxx"/>
                    <div class="" style="display: none;">
                        <label class="layui-form-label qbdms-label" title="主键">主键</label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" name="id"  placeholder="请输入" fieldname="id"
                                   autocomplete="off" class="layui-input" maxlength="50">
                        </div>
                    </div>
                    <div class="containDIv56">
                        <label class="layui-form-label qbdms-label" title="知识名称">知识名称<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" name="knowledgeName"  placeholder="请输入" lay-verify="required" lay-reqtext="知识名称是必填项"
                                   autocomplete="off" class="layui-input" maxlength="50" fieldname="knowledgeName" >
                        </div>
                    </div>
                    <div class="containDIv">
                        <label class="layui-form-label qbdms-label" title="密级">密级<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                                <@secSelect.sec_select required=true data_src=1 name="secret"/>
                        </div>
                    </div>
                    <div class="containDIv">
                        <label class="layui-form-label qbdms-label" title="知识分类1">知识分类1<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <select id="knowledgeClassification" name="knowledgeClassification"  lay-filter="zsfl1" lay-verify="required" lay-reqtext="知识分类1是必填项" lay-search=""></select>
                        </div>
                    </div>
                    <div class="containDIv">
                        <label class="layui-form-label qbdms-label" title="知识分类2">知识分类2</label>
                        <div class="layui-input-block qbdms-input">
                            <select id="knowledgeClassification2" name="knowledgeClassification2"  lay-filter="zsfl2" lay-verify="" lay-search=""></select>
                        </div>
                    </div>

                    <div class="containDIv">
                        <label class="layui-form-label qbdms-label" title="可见范围">可见范围<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <select  id="visibleRange" name="visibleRange"  lay-filter="visibleRange" lay-verify="required" lay-reqtext="可见范围是必填项" lay-search=""></select>
                        </div>
                    </div>
                    <div class="containDIv">
                        <label class="layui-form-label qbdms-label" title="是否发送推送消息">是否推送<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <select  id="pushState"   name="pushState"  lay-filter="pushState" lay-verify="required" lay-reqtext="是否推送是必填项" lay-search=""></select>
                        </div>
                    </div>



                    <div class="">
                        <label class="layui-form-label qbdms-label" title="关键词">关键词<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" name="keyWord"  placeholder="请输入" autocomplete="off" class="layui-input"  lay-verify="required"
                                   maxlength="50" fieldname="keyWord"  lay-reqtext="关键词是必填项" style="width: 22%;float: left">
                            <i class="qbdms-fileUpText" style="height: 40px;line-height: 40px">多个关键词需要用空格间隔</i>
                        </div>
                    </div>
                    <div >
                        <label class="layui-form-label qbdms-label" title="上传附件">上传附件<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <button type="button" class="layui-btn iconfont iconupload fileUpload qbdms-fileUp" id="enclosureList">上传附件</button>
                            <i class="qbdms-fileUpText">支持单个附件上传，附件格式：doc  docx    pdf xls xlsx，文件大小限制不超过100M</i>
                            <input type="text" id="enclosure" class="uploadInput" name="enclosure"  lay-verify="required"  lay-reqtext="上传附件是必填项"
                                   fieldname="attachmentUrl" style="display: none">
                            <div class="uploadFileList" fileUploadName="enclosure" style="padding-top: 9px;"></div>
                        </div>
                    </div>
                    <div style="width: 76%">
                        <label class="layui-form-label qbdms-label" title="文件摘要">文件摘要</label>
                        <div class="layui-input-block qbdms-input">
                            <textarea type="text" name="summaryDocument"  placeholder="请输入" autocomplete="off" class="layui-input"
                                      maxlength="250" fieldname="summaryDocument" style="min-height:64px;padding-top: 5px"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-top: 48px">
                    <p style="text-align: left;margin-left: 104px;">
                        <a lay-submit lay-filter="wQbdQualityKnow" class="layui-btn privateSubmit qbdms-oneBtn" requrl="${ctx}/qbdms/wQbdQualityKnow/save">提交</a>
                        <button type="reset" id="closeWindow" style="margin-left: 10px;" class="layui-btn   layui-btn-sm btn-save qbdms-oneBtnLine">取消</button>
                    </p>
                </div>
            </form>
        </div>
</div>
    </div>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script src="${ctx}/json/comboselect.js" type="text/javascript"></script>
    <script>
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'setter', 'layer', 'upload', 'common','propsHandle', 'jquery', 'publicMethods' ,'qbdmsForm'], function () {
        var laydate = layui.laydate;
        var common = layui.common;
        var $ = layui.jquery;
        var upload = layui.upload;
        var setter = layui.setter;
        var  form = layui.qbdmsForm;
        var  propsHandle = layui.propsHandle;
        var publicMethods = layui.publicMethods;
        var loading;
        //关闭当前页面
        $("#closeWindow").click(function () {
            window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdQualityKnow/view/list';
        });
        //关闭当前页面
        $(".closeWindow").click(function () {
            window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdQualityKnow/view/list';
        });
        //下载附件
        window.downFile = function (obj) {
            var fileId = $(obj).parents("span").attr("fileId");
            window.location.href = serverPath.qbdmsPath + setter.extendLinkPath + "attachFile/download?fileId=" + fileId;
        }

        //构建file的字符串
        function constructFileStr() {
            var filesJsonStr = "";
            $(this).find(".file-id").each(function () {
                var fileId = $(this).attr("fileid");
                var fileName = $(this).find("span").text();
                var fileLevel = $(this).find("option:selected").val();
                var fileLevelText = $(this).find("option:selected").text();
                filesJsonStr += '{"fileId":"' + fileId + '","fileName":"' + fileName + '","fileLevel":"' + fileLevel + '", "fileLevelText":"' + fileLevelText + '"},';
            });
            filesJsonStr = filesJsonStr.substring(0, filesJsonStr.length - 1);
            if (filesJsonStr != "") {
                filesJsonStr = '[' + filesJsonStr + ']';
            }
            var fileUploadName = $(this).attr("fileUploadName");
            $("#" + fileUploadName).val(filesJsonStr);
        }
        var runId = "${runId}";
        if(runId == null || runId == ''){
            $("#hideAndShow").show();
        }
        var secSelect = '<@secSelect.sec_select   required=true data_src=1 hasBlank=false/>';
        // common.uploadfun(".fileUpload",'${wjszsdsxlx}',"${fileManagementUploadType}",secSelect,false);
        var mainParam = {acceptMime:'${selectType}',exts:'${uploadType}',upLoadSize:102400,secSelect:secSelect,isSub:false};
        common.uploadfun(".fileUpload",mainParam);

        // 删除
        $(document).on('click', '.deleteFile', function () {
            $(this).parent().parent().siblings("button").show()
            $(this).parent().remove();
            $(".uploadFileList").each(function (i,v) {
                common.constructFileStr(v)
            });
        });
        var indexxx;
        common.updateForm({
            name:'wQbdQualityKnowDataForm',
            idValue:"${id}",
            primary:"id",
            beforeSubmitFun: function (data) {
                //- 附件密级不能高于表单密级 开始 ------------------------------------------------------
                var selectMaxVal = 0;
                var formSecretVal = $("[name='secret']").val();
                $(".fileSecLevel select").each(function () {
                    selectMaxVal = selectMaxVal >= $(this).val() ? selectMaxVal : $(this).val();
                });

                if (selectMaxVal > formSecretVal) {
                    layer.msg('附件密级不能高于表单密级。', {icon: 5});
                    return false;
                }
                //- 附件密级不能高于表单密级 结束 ------------------------------------------------------
                $(".uploadFileList").each(function (i,v) {
                    common.constructFileStr(v)
                });

                var files=[];
                //整理上传附件的隐藏域，将提交的字符串转为json对象
                $(".uploadInput").each(function () {
                    var uploadName = $(this).attr("name");
                    if (!$(this).val()) {
                        return;
                    }
                    data.field[uploadName] = eval($(this).val());
                    files=files.concat(eval($(this).val()));
                });
                var flag;
                flag= common.setFileLevel(files);
                if (flag){
                    indexxx = layer.load(1);
                }
                return  flag;

            },
            getCallback: function (data) {
                //-修改页面 初始化附件组件 开始 ------------------------------------------
                $('.uploadFileList').each(function () {
                    var fileUploadName = $(this).attr("fileUploadName");
                    var jsonFile = data.data[fileUploadName];
                    var files = eval(jsonFile);
                    if (files) {
                        for (var i = 0; i < files.length; i++) {
                            var fileLevel = files[i].fileLevel;
                            var fileLevelText = files[i].fileLevelText;
                            var fileSec = '<div class="fileSecLevel fileSecXg layui-input-inline">' + '<@secSelect.sec_select data_src=1 hasBlank=false/>' + "</div>";
                            var newStr = '<span class="file-id" style="margin-right: 20px;" fileId=' + files[i].fileId + ' fileLevelText="' + fileLevelText + '">' + fileSec + '<span class="file-name" title="点击下载文件" onclick="downFile(this)"><i class="iconfont data-iconcommon_fujian" style="margin-right: 5px"></i>' + files[i].fileName + '</span><i class="iconfont data-iconcommon_close deleteFile" ></i></span>';
                            $(this).html(newStr);
                            $(this).find("select:last").val(fileLevel);
                            //$(this).find("select:last").attr("disabled", "disabled");
                        }
                    }
                });
                //-修改页面 初始化附件组件 结束 ------------------------------------------

                //-修改页面 级联下拉 原因分类 开始 ------------------------------------------
                comboselect.setDefaultValueByArr(data.data["knowledgeClassification"], data.data["knowledgeClassification2"]);
                form.render("select");
                //-修改页面 级联下拉 原因分类 结束 ------------------------------------------


            },
            updateCallback:function (data) {
                layer.close(indexxx);
                if (common.filterRecord(data)) {
                    if($(".privateSubmit")){
                        $(".privateSubmit").attr("disabled",false).css("pointer-events","auto");
                    }
                    layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'}, function (index) {
                        layer.close(index);
                        window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdQualityKnow/view/list';
                    });
                } else {
                    layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                }
                return false;
            }
        });

        //- 知识分类初始化 绑事件 开始 -------------------------------------------------------------

        var kjfwList = eval('${kjfwList}'); //可见范围
        common.initDicData("visibleRange", kjfwList);

        var spfstsxxList = eval('${spfstsxxList}'); //是否推送
        common.initDicData("pushState", spfstsxxList);


        var zsfl1List = eval('${zsfl1List}'); //知识分类
        var typeId = "${typeId}";
        comboselect = ComboSelectFactory(zsfl1List, 'knowledgeClassification', 'knowledgeClassification2');
        comboselect.setProperties({
            idKey: 'dicId',
            valueKey: 'dicId',
            textKey: 'itemValue',
            parentIdKey: 'parentId',
            topParentValue: typeId
        });
        form.render("select");
        form.on('select(zsfl1)', function(){
            comboselect.eventHandle(document.getElementById("knowledgeClassification"),0)();
            form.render("select");
        });
    });
</script>
</body>
</html>